package com.example.demo1.controller;

import com.example.demo1.pojo.po.Emp;
import com.example.demo1.pojo.po.User;
import com.example.demo1.service.TokenService;
import com.example.demo1.service.inpl.TokenServiceImpl;
import com.example.demo1.util.RedisAPI;
import com.example.demo1.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(description = "用于测试接口")
@RestController
public class HelloController {

    @Autowired
    private RedisAPI redisAPI;


    //默认get请求方法
    @ApiOperation("hello接口，说hello")
    @GetMapping("/hello")
    public ResultUtil sayHello() {

        return ResultUtil.success("Hello,SpringBoot!");
    }

    /**
     * 接口API
     * @return
     */
    @ApiOperation("list接口,返回list集合")
    @GetMapping("/list")
    public ResultUtil returnList(){
        List<String> list=new ArrayList<String>();
        list.add("你");
        list.add("好");
        list.add("帅");
        return ResultUtil.success(list);
    }

    @ApiOperation("user接口，返回user信息，并redis储存")
    @GetMapping("/user")
    public ResultUtil returnUser(){
        User user=new User();
        user.setUserName("马伟");
        user.setUserAge(20);
        user.setUserSex("男的");
        redisAPI.set("name",user.getUserName());
        redisAPI.set("age",user.getUserAge().toString());
        redisAPI.set("sex",user.getUserSex());
        return ResultUtil.success(user);
    }


    @ApiOperation("one接口，获取Emp信息")
    @GetMapping("/one")
    public ResultUtil returnby(){
        Emp emp=new Emp();
        emp.getEmpAge();
        emp.getEmpName();
        emp.getEmpSex();
        return ResultUtil.success(emp);
    }
    /*@GetMapping("kkk")
    public ResultUtil onee() {
        TokenService tokenService=new TokenServiceImpl();
        User user=new User();
        user.setUserName("张三");
        user.setUserAge(20);
        user.setUserSex("男");
        user.setUserCode("2368702155@qq.com");
        user.setId(1);
        redisAPI.set("name",user.getUserName());
        redisAPI.set("id",user.getId().toString());
        System.out.println(tokenService.generatorToken("",user));
        return ResultUtil.success(user);
    }*/
}
